<template>
  <div>
    <template>
      <el-form
        ref="userForm"
        :rules="rules"
        :model="userInfo"
        label-width="120px"
        style="margin-left: 120px; margin-top: 30px"
      >
        <el-form-item label="姓名:" prop="username">
          <el-input v-model="userInfo.username" style="width:300px" />
        </el-form-item>
        <el-form-item label="密码:" prop="password">
          <el-input v-model="userInfo.password" type="password" style="width:300px" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="updateUserInfo">更新</el-button>
        </el-form-item>
      </el-form>
    </template>
  </div>
</template>
<script>
import { getUserDetailById } from '@/api/user'
import { saveUserDetailById } from '@/api/employees'
export default {
  name: 'LoginSetting',
  data() {
    return {
      userInfo: {
        username: '',
        password: ''
      },
      rules: {
        username: [{ required: true, message: '用户名不能为空', triggler: 'blur' }],
        password: [{ required: true, message: '密码不能为空', triggler: 'blur' }]
      }
    }
  },
  computed: {
  },
  created() {
    this.loadUserDetail()
  },
  methods: {
    async loadUserDetail() {
      const res = await getUserDetailById(this.$route.query.id)
      console.log(res, '获取用户信息')
      // const { username, password } = res.data
      // this.userInfo = { username, password }
      this.userInfo = res.data
    },
    updateUserInfo() {
      this.$refs.userForm.validate(async(valid) => {
        if (valid) {
          const res = await saveUserDetailById(this.userInfo)
          console.log(res, '更新用户信息')
          this.$message.success('修改密码成功')
        }
      })
    }
  }
}
</script>
<style lang='less'  scoped>

</style>
